package com.qf.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.serviceimpl
 * @Description:
 * @Date 2022/10/13 20:18
 */
@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {

    @Autowired
    DtsGoodsProductMapper dtsGoodsProductMapper;

    @Override
    public long getCount() {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getDeleted,false);

        return dtsGoodsProductMapper.selectCount(wrapper);
    }

    @Override
    public void insert(DtsGoodsProduct product) {
        product.setDeleted(false);
        product.setUpdateTime(new Date());
        product.setAddTime(new Date());

        dtsGoodsProductMapper.insert(product);
    }

    @Override
    public List<DtsGoodsProduct> findByGoodsId(Integer goodsId) {

        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId,goodsId);
        wrapper.eq(DtsGoodsProduct::getDeleted,false);
        return dtsGoodsProductMapper.selectList(wrapper);

    }

    @Override
    public void delete(Integer id) {
        dtsGoodsProductMapper.deleteById(id);
    }
}
